package com.fwtai.core;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import com.fwtai.tool.IdBuilder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 异步处理
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2020-04-10 20:13
 * @QQ号码 444141300
 * @Email service@yinlz.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class AsyncDao{

  @Resource
  private DaoHandle dao;

  public void updateSucceed(final String username){
    dao.execute("sys_user.updateSucceed",username);
  }

  public void updateBrowse(final String kid){
    dao.execute("api_knowledge.updateBrowse",kid);
  }

  public void updateVideoBrowse(final String kid){
    dao.execute("api_videos.updateVideoBrowse",kid);
  }

  public void updateReadInform(final String kid,final String loginId){
    final PageFormData formData = new PageFormData();
    formData.put("informId",kid);
    formData.put("loginId",loginId);
    formData.put("readId",new IdBuilder().getId121L());
    dao.execute("api_inform.updateReadInform",formData);
  }

  public void delCaseInform(final String kid){
    dao.execute("api_legal_case.delCaseInform",kid);//删除案件进展
  }

  public List<Map<String, Object>> getDetails(final String kid){
    return dao.queryForListMap("api_legal_case.getDetails",kid);
  }

  @Transactional
  public void delDetails(final String kid){
    dao.execute("api_legal_case.delDetailsAttach",kid);
    dao.execute("api_legal_case.delDetailsImg",kid);
  }

  /**律师自己发布的案件通知到当事人*/
  public List<String> getPartysLawyer(final String kid){
    return dao.queryListString("api_legal_case.getPartysLawyer",kid);
  }

  /**普通用户或合伙人发布的案件通知到当事人*/
  public List<String> getPartysUser(final String kid){
    return dao.queryListString("api_legal_case.getPartysUser",kid);
  }

  public void addPartys(final ArrayList<HashMap<String,String>> list){
    dao.execute("api_legal_case.addPartys",list);
  }

  public void addHome(final PageFormData formData){
    dao.execute("api_statistics.addHome",formData);
  }

  @Transactional
  public void updateWechat(final PageFormData formData){
    dao.execute("api_sys_user.delWechat",formData.getString("openId"));
    dao.execute("api_sys_user.updateWechat",formData);
  }

  @Transactional
  public void addSmsRecord(final PageFormData formData){
    dao.execute("all_user.addSms",formData);
    dao.execute("all_user.addRecord",formData);
  }

  public void addMaterialOrderLog(final PageFormData formData){
    dao.execute("api_order_log.addMaterialOrderLog",formData);
  }

  public void addServiceOrderLog(final PageFormData formData){
    dao.execute("api_order_log.addServiceOrderLog",formData);
  }

  /**同1账号1天仅发送一次*/
  public List<String> getConsult(final PageFormData formData){
      return dao.queryListString("api_consult.getConsult",formData);
  }

  /**同1账号1天仅发送一次*/
  public List<HashMap<String, String>> getLawyerConsult(final PageFormData formData){
    return dao.queryForListString("api_consult.getLawyerConsult",formData);
  }

  public void updateReadForUserLawyer(final PageFormData formData){
    dao.execute("api_consult.updateReadForUserLawyer",formData);
  }

  public void updateReadForLawyerUser(final PageFormData formData){
    dao.execute("api_consult.updateReadForLawyerUser",formData);
  }

  public String getServiceAd(final long serviceId){
    return dao.queryForString("service.getServiceAd",serviceId);
  }

  public void delServiceAd(final PageFormData formData){
    dao.execute("service.deleteAd",formData);//硬删除广告
  }

  //若咨询的用户删除自己的咨询时连同已回复的咨询一起删除
  public void delReplay(final Long kid){
    dao.execute("api_advisory.delReplay",kid);
  }

  /**批量站内认证信息*/
  public void addBatchAuth(final ArrayList<HashMap<String,Object>> list){
    dao.execute("partner.addBatchAuth",list);
  }

  public void addMerchantUser(final PageFormData formData){
    dao.execute("api_merchant.addMerchantUser",formData);
  }

  public List<String> getMerchantPhones(final long merchantId){
    return dao.queryListString("api_merchant.getMerchantPhones",merchantId);
  }

  public void addMerchant(final PageFormData formData){
    dao.execute("merchant.addMerchant",formData);
  }

  public void updateMaxRatio(final HashMap<String,Object> params){
    dao.execute("merchant.updateMaxRatio",params);
  }

  public void addConsultRecord(final PageFormData formData){
    dao.execute("api_statistics.addConsultRecord",formData);
  }

  public void addActivityRecord(final HashMap<String,Long> params){
    dao.execute("api_buy.addActivityRecord",params);
  }

  public void updateGoodsPv(final long kid){
    dao.execute("api_mall.updateGoodsPv",kid);
  }

  public void updateProductPv(final long kid){
    dao.execute("api_product_show.updateProductPv",kid);
  }

  public void editCheckTime(final HashMap<String,Object> params){
    dao.execute("api_goods.editCheckTime",params);
  }

  public void updateCheckTotal(final String code){
    dao.execute("api_goods.updateCheckTotal",code);
  }
}